<div class="content-wrapper" id="rule">
    <el-form ref="form" :model="template" label-width="180px">
        <el-form-item label="模板名称">
            <el-input v-model="template.templateName"></el-input>
        </el-form-item>
        <el-form-item label="标题头在第几行">
            <el-input v-model="template.titleHeadLine"  ></el-input>
        </el-form-item>
        <el-form-item label="标题头的值">
            <el-input  v-model="template.titleHead" placeholder="英文逗号隔开, 如：交易日期,收入金额,支出金额,余额,对方账号,对方客户名称,摘要"></el-input>
        </el-form-item>
        <el-form-item label="模板描述">
            <el-input  v-model="template.templateDesc" placeholder="如：每4行是一条完整的数据，交易主体根据借贷标识区分"></el-input>
        </el-form-item>
        <el-form-item label="excel的类型">
            <el-radio-group v-model="template.excelType">
                <el-radio :label="0" >流水详情表</el-radio>
                <el-radio :label="1" >开户信息表</el-radio>
            </el-radio-group>
        </el-form-item>
        <el-form-item label="有无需要跳过的值">
            <el-radio-group v-model="template.isEnd">
                <el-radio :label="0" >无</el-radio>
                <el-radio :label="1" >有</el-radio>
                <span  v-if="template.isEnd">
                    <el-button @click="addEndInfo">新增需要跳过的值</el-button>
                </span>
            </el-radio-group>
        </el-form-item>
            <div v-if="template.isEnd" class="isEnd">
                <el-form-item label="需要跳过的值" v-for="(item, index) in template.endInfo" >
                    <el-input v-model="template.endInfo[index]" placeholder="英文逗号隔开, 如：根据查询条件.+,个人活期明细信息-新一代,查无结果"></el-input>
                    <el-button @click="removeEndInfo(index)">删除</el-button>
                </el-form-item>
            </div>
        <el-form-item label="流入流出标志">
            <el-select v-model="template.isInputOut.type" placeholder="请选择流入流出标志">
                <el-option label="某列包含收付标志" value="1"></el-option>
                <el-option label="两列比较" value="2"></el-option>
                <el-option label="和上一个对象比较" value="3"></el-option>
                <el-option label="定值" value="4"></el-option>
            </el-select>
        </el-form-item>
            <div class="inputOut">
                <div v-if="template.isInputOut.type==1">
                    <el-form-item label="第几列">
                        <el-input v-model="template.isInputOut.col"  placeholder="如：1  表示第2列 "></el-input>
                    </el-form-item>
                    <el-form-item label="流入标记">
                        <el-input v-model="template.isInputOut.input" placeholder="如：贷  表示流入 "></el-input>
                    </el-form-item>
                    <el-form-item label="流出标记">
                        <el-input v-model="template.isInputOut.out" placeholder="如：借  表示流出 "></el-input>
                    </el-form-item>
                </div>
                <div v-else-if="template.isInputOut.type == 2">
                    <el-form-item label="两列比较">
                        <el-input v-model="template.isInputOut.col" placeholder="记住，当第一个数是流入,英文逗号隔开 如：1,2 "></el-input>
                    </el-form-item>
                </div>
                <div v-else-if="template.isInputOut.type == 3">
                    <el-form-item label="上一个对象比较">
                        <el-input v-model="template.isInputOut.col" placeholder="记住，交易金额字段放在前面，剩余金额放在后面 如：accountMoney,surplusMoney "></el-input>
                    </el-form-item>
                </div>
                <div v-else-if="template.isInputOut.type == 4">
                    <el-form-item label="定值">
                        <el-select v-model="template.isInputOut.val" placeholder="插入的数据都是定值。即都是流入或者流出">
                            <el-option label="流入" value="0"></el-option>
                            <el-option label="流出" value="1"></el-option>
                        </el-select>
                    </el-form-item>
                </div>
            </div>
        <el-form-item label="是否是复杂模板">
            <el-radio-group v-model="template.isComplex">
                <el-radio :label="0" >否</el-radio>
                <el-radio :label="1" >是</el-radio>
            </el-radio-group>
        </el-form-item>
        <div v-if="template.isComplex">
            <el-form-item label="是否是循环标题头">
                <el-radio-group v-model="template.isLoop">
                    <el-radio :label="0" >否</el-radio>
                    <el-radio :label="1" >是</el-radio>
                </el-radio-group>
            </el-form-item>
            <el-form-item label="是否有公共的附加信息">
                <el-radio-group v-model="template.isTitleAttachInfo">
                    <el-radio :label="0" >否</el-radio>
                    <el-radio :label="1" >是</el-radio>
                </el-radio-group>
                <span  v-if="template.isTitleAttachInfo">
                    <el-button @click="addCommonAttachInfo">新增公共的附加信息</el-button>
                </span>
            </el-form-item>
                <div v-if="template.isTitleAttachInfo">
                    <div class="commonRow" v-for="(item1, index1) in template.titleAttachInfoDetail">
                        <el-form-item label="第几行">
                            <el-input v-model="item1.row" placeholder="如：1  表示第2行 "></el-input>
                            <el-button @click="addCommonAttachCol(index1)">新增列</el-button>
                            <el-button @click="removeCommonAttachCol(index1)">删除列</el-button>
                            <el-button @click="removeCommonAttachRow(index1)">删除行</el-button>
                        </el-form-item>
                        <div class="commonAttachCol" v-for="(item2, index2) in item1.colList ">
                            <el-form-item label="第几列">
                                <el-input v-model="item2.col" placeholder="如：1  表示第2列 "></el-input>
                            </el-form-item>
                            <el-form-item label="正则">
                                <el-input v-model="item2.reg" placeholder="正则表达式，请测试好再填写，专业人士用 "></el-input>
                            </el-form-item>
                            <el-button @click="addCommonAttachColFiled(index1,index2)">新增字段</el-button>
                            <el-button @click="removeCommonAttachColFiled(index1,index2)">删除字段</el-button>
                            <div  class="commonAttachColField">
                                <div v-for="(item3, index3) in  item2.obj" class="commonAttachColFieldBlock">
                                    <el-form-item label="字段名字">
                                        <el-input v-model="item3.fieldName" placeholder="如：accountBody  表示交易主体 "></el-input>
                                    </el-form-item>
                                    <el-form-item label="字段类型">
                                        <el-select v-model="item3.fieldType" placeholder="请选择字段类型">
                                            <el-option label="字符串" value="1"></el-option>
                                            <el-option label="整数类型" value="2"></el-option>
                                            <el-option label="小数类型" value="3"></el-option>
                                            <el-option label="时间类型" value="4"></el-option>
                                        </el-select>
                                    </el-form-item>
                                    <el-form-item label="字段位置">
                                        <el-input v-model="item3.index" placeholder="如：0  表示用正则匹配的列表的第一个值 "></el-input>
                                    </el-form-item>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            <el-form-item label="是否有标题头附加信息">
                <el-radio-group v-model="template.isTitleInfo">
                    <el-radio :label="0" >否</el-radio>
                    <el-radio :label="1" >是</el-radio>
                </el-radio-group>
                <span  v-if="template.isTitleInfo">
                    <el-button @click="addTitleInfo()">新增标题头附加信息</el-button>
                </span>
            </el-form-item>
                <div class="isTitleInfo" v-if="template.isTitleInfo">
                    <div class="commonRow" v-for="(item1, index1) in template.titleInfoDetail">
                        <el-form-item  label="第几列">
                            <el-input placeholder="如：1  表示第2列 "  v-model="item1.col"></el-input>
                            <el-button @click="removeTitleInfo(index1)">删除标题头附加信息</el-button>
                        </el-form-item>
                        <el-form-item  label="正则">
                            <el-input  placeholder="正则表达式，请测试好再填写，专业人士用 " v-model="item1.reg"></el-input>
                            <el-button @click="addTitleInfoFiled(index1)">新增标题头字段</el-button>
                            <el-button @click="removeTitleInfoFiled(index1)">删除新增标题头字段</el-button>
                        </el-form-item>
                        <div class="isTitleInfoFiled" v-for="(item2, index2) in  item1.obj">
                            <el-form-item label="字段名字">
                                <el-input v-model="item2.fieldName" placeholder="如：accountBody  表示交易主体 "></el-input>
                            </el-form-item>
                            <el-form-item label="字段类型">
                                <el-select v-model="item2.fieldType" placeholder="请选择字段类型">
                                    <el-option label="字符串" value="1"></el-option>
                                    <el-option label="整数类型" value="2"></el-option>
                                    <el-option label="小数类型" value="3"></el-option>
                                    <el-option label="时间类型" value="4"></el-option>
                                </el-select>
                            </el-form-item>
                            <el-form-item label="字段位置">
                                <el-input v-model="item2.index" placeholder="如：0  表示用正则匹配的列表的第一个值 "></el-input>
                            </el-form-item>
                        </div>
                    </div>
                </div>
            <el-form-item label="标题头信息是否循环">
                <el-radio-group v-model="template.isLoopTitleInfo">
                    <el-radio :label="0" >否</el-radio>
                    <el-radio :label="1" >是</el-radio>
                </el-radio-group>
            </el-form-item>
            <el-form-item label="是否有多个sheet">
                <el-radio-group v-model="template.isMultiSheet">
                    <el-radio :label="0" >否</el-radio>
                    <el-radio :label="1" >是</el-radio>
                </el-radio-group>
            </el-form-item>
                <div class="multiSheet" v-if="template.isMultiSheet">
                    <el-form-item label="字段类型">
                        <el-select v-model="template.multiSheetDetail.type" placeholder="请选择字段类型">
                            <el-option label="只解析包含的sheet名" value="1"></el-option>
                        </el-select>
                        <el-button @click="addMultiSheet()">新增多sheet信息</el-button>
                        <el-button @click="removeMultiSheet()">删除多sheet信息</el-button>
                    </el-form-item>
                        <div class="multiSheetName" v-for="(item, index) in  template.multiSheetDetail.obj">
                            <el-form-item label="sheet名字">
                                <el-input v-model="item.sheetName" placeholder="如：交易明细  表示只解析包含包含交易明细的sheet。 "></el-input>
                            </el-form-item>
                        </div>
                </div>
            <el-form-item label="是否有多个标题头">
                <el-radio-group v-model="template.isMultiTitleHead">
                    <el-radio :label="0" >否</el-radio>
                    <el-radio :label="1" >是</el-radio>
                </el-radio-group>
            </el-form-item>
                <div class="multiTitleHead" v-if="template.isMultiTitleHead">
                    <el-form-item label="第二列标题头的信息">
                        <el-input v-model="template.multiTitleHeadDetail.col" placeholder="第二列标题头的信息 英文逗号隔开 "></el-input>
                        <el-button @click="addMultiTitleHeadFiled()">新增字段信息</el-button>
                    </el-form-item>
                    <div class="multiTitleHeadField" v-for="(item, index) in template.multiTitleHeadDetail.map">
                        <el-form-item label="第几列">
                            <el-input v-model="item.col" placeholder="第二列标题头的信息 英文逗号隔开 "></el-input>
                        </el-form-item>
                        <el-form-item label="字段名称">
                            <el-input v-model="item.classField" placeholder="第二列标题头的信息 英文逗号隔开 "></el-input>
                        </el-form-item>
                        <el-form-item label="excel标题的值">
                            <el-input v-model="item.titleValues" placeholder="第二列标题头的信息 英文逗号隔开 "></el-input>
                        </el-form-item>
                        <el-form-item label="字段类型">
                            <el-select v-model="item.fieldType" placeholder="请选择字段类型">
                                <el-option label="字符串" value="1"></el-option>
                                <el-option label="整数类型" value="2"></el-option>
                                <el-option label="小数类型" value="3"></el-option>
                                <el-option label="时间类型" value="4"></el-option>
                            </el-select>
                        </el-form-item>
                        <el-button @click="removeMultiTitleHeadFiled(index)">删除字段信息</el-button>
                    </div>
                </div>
            <el-form-item label="是否是特殊的模板">
                <el-radio-group v-model="template.isSpecial">
                    <el-radio :label="0" >否</el-radio>
                    <el-radio :label="1" >是</el-radio>
                </el-radio-group>
            </el-form-item>
                <div class="special" v-if="template.isSpecial">
                    <el-form-item label="字段名字" placeholder="如：sign  表示收付标志 ">
                        <el-input v-model="template.specialDetail.field"></el-input>
                    </el-form-item>
                    <el-form-item label="符合的条件" placeholder="如：0  表示当sign的值等于0的时候才进行对调匹配 ">
                        <el-input v-model="template.specialDetail.equal"></el-input>
                    </el-form-item>
                </div>
        </div>
        <el-form-item label="是否上传阿里云">
            <el-radio-group v-model="isUpload">
                <el-radio :label="0" >否</el-radio>
                <el-radio :label="1" >是</el-radio>
            </el-radio-group>
        </el-form-item>
        <div class="uploadFile" v-if="isUpload">
            <el-upload
                    class="upload-demo"
                    action="/rule/uploadFile"
                    :on-preview="handlePreview"
                    :on-remove="handleRemove"
                    :before-remove="beforeRemove"
                    multiple
                    :limit="3"
                    :on-exceed="handleExceed"
                    :file-list="fileList">
                <el-button size="small" type="primary">点击上传</el-button>
                <div slot="tip" class="el-upload__tip">上传到阿里云服务器，管理员会审批模板是否正确</div>
            </el-upload>
        </div>
        <el-form-item>
            <el-button type="primary" @click="onSubmit">立即创建</el-button>
            <el-button>取消</el-button>
        </el-form-item>
    </el-form>
</div>
<!--<script src="https://cdn.bootcss.com/vue/2.6.9/vue.min.js"></script>
<link rel="stylesheet" href="https://unpkg.com/element-ui/lib/theme-chalk/index.css">
<script src="https://unpkg.com/element-ui/lib/index.js"></script>
<script src="https://unpkg.com/axios/dist/axios.min.js"></script>
<script src="https://cdn.bootcss.com/jquery/3.3.1/jquery.min.js"></script>-->

<link rel="stylesheet" href="${ctx}/bower_components/vue/css/element-ui.css">
<script src="${ctx}/bower_components/vue/js/vue.min.js"></script>
<script src="${ctx}/bower_components/vue/js/element-ui.js"></script>
<script src="${ctx}/bower_components/vue/js/axios.js"></script>
<script type="text/javascript">
    let ruleId = '${ruleId}';
    window.onload=function () {
        if (ruleId!=0) {
            vm.findExcelRuleById(ruleId);
        }
    }
    var vm=new Vue({
        el: '#rule',
        data:{
            fileList: [],
            isUpload:0,
            template: {
                isEnd: 0,
                isLoop: 0,
                isComplex: 0,
                titleHead:'',
                templateDesc:'',
                excelType:0,
                isTitleAttachInfo: 0,
                isTitleInfo: 0,
                isLoopTitleInfo: 0,
                isMultiSheet: 0,
                isMultiTitleHead: 0,
                isSpecial:0,
                titleHeadLine: 0,
                templateName: '',
                endInfo: [''],//需要跳过的值数组
                titleAttachInfoDetail:[{
                    row: '',
                    colList:[{
                        col:'',
                        reg:'',
                        obj:[{
                            fieldName:'',
                            fieldType:'',
                            index:''
                        }]
                    }]
                }],
                titleInfoDetail: [
                    {
                        col:'',
                        reg:'',
                        obj:[{
                            fieldName:'',
                            fieldType:'',
                            index:''
                        }]
                    }
                ],
                multiSheetDetail:{type: '1',obj:[{sheetName:''}]},
                isInputOut:{
                    type:'1'
                },
                multiTitleHeadDetail:{map:[{col:'',className:'com.mairuide.bill.DealFlow',classField:'',titleValues:'',fieldType:''}],col:""},
                specialDetail:{field:'',equal:''}
            },
        },
        methods:{
            handleRemove(file, fileList) {   //移除图片
                console.log(file.name);
                axios.post('${ctx}/rule/removeFile','fileName='+file.name).then(function (response){
                    console.log(response.data)
                })
            },
            handlePreview(file) {
                console.log("我点击了"+file.name);
            },
            handleExceed(files, fileList) {
                this.$message.warning('当前限制选择 3 个文件，本次选择了'+ files.length +'个文件，共选择了'+ files.length + fileList.length+ '个文件');
            },
            beforeRemove(file, fileList) {
                return this.$confirm("确定移除 "+file.name+"么？");
            },
            findExcelRuleById(id){
                axios.get('${ctx}/rule/findExcelRuleById/'+id, {
                }).then(function (response) {
                    temp=response.data.data;
                    vm.template.templateName=temp.templateName;
                    vm.template.titleHeadLine=temp.titleHeadLine;
                    vm.template.isLoop=temp.isLoop;
                    vm.template.isTitleAttachInfo=temp.isTitleAttachInfo;
                    vm.template.titleAttachInfoDetail=JSON.parse(temp.titleAttachInfoDetail);
                    vm.template.isEnd=temp.isEnd;
                    vm.template.endInfo=JSON.parse(temp.endInfo);
                    vm.template.isComplex=temp.isComplex;
                    vm.template.titleHead=temp.titleHead;
                    vm.template.isTitleInfo=temp.isTitleInfo;
                    vm.template.titleInfoDetail=JSON.parse(temp.titleInfoDetail);
                    vm.template.isLoopTitleInfo=temp.isLoopTitleInfo;
                    vm.template.isMultiSheet=temp.isMultiSheet;
                    vm.template.multiSheetDetail=JSON.parse(temp.multiSheetDetail);
                    vm.template.isInputOut=JSON.parse(temp.isInputOut);
                    vm.template.isMultiTitleHead=temp.isMultiTitleHead;
                    vm.template.multiTitleHeadDetail=JSON.parse(temp.multiTitleHeadDetail);
                    vm.template.isSpecial=temp.isSpecial;
                    vm.template.specialDetail=JSON.parse(temp.specialDetail);
                    vm.template.templateDesc=temp.templateDesc;
                    vm.template.id=temp.id;
                    vm.template.excelType=temp.excelType;
                    console.log(vm.template)
                })
            },
            onSubmit(){
                let s=this.checkTempleteInfo();
                if (!s) return;
                let template = this.checkTemplate()
                console.log(template);
                let endInfo = template.endInfo;
                let titleAttachInfoDetail = template.titleAttachInfoDetail;
                let titleInfoDetail= template.titleInfoDetail;
                let multiSheetDetail = template.multiSheetDetail;
                let isInputOut= template.isInputOut;
                let multiTitleHeadDetail= template.multiTitleHeadDetail;
                let specialDetail =  template.specialDetail;
                axios.post('${ctx}/rule/addExcelRule',{
                    id:template.id,
                    excelType:template.excelType,
                    templateName: template.templateName,
                    titleHeadLine:template.titleHeadLine,
                    isLoop:template.isLoop,
                    isTitleAttachInfo: template.isTitleAttachInfo,
                    titleAttachInfoDetail:titleAttachInfoDetail,
                    isEnd: template.isEnd,
                    endInfo: endInfo,
                    isComplex: template.isComplex,
                    titleHead: template.titleHead,
                    isTitleInfo: template.isTitleInfo,
                    titleInfoDetail: titleInfoDetail,
                    isLoopTitleInfo: template.isLoopTitleInfo,
                    isMultiSheet:template.isMultiSheet,
                    multiSheetDetail: multiSheetDetail,
                    isInputOut: isInputOut,
                    isMultiTitleHead: template.isMultiTitleHead,
                    multiTitleHeadDetail: multiTitleHeadDetail,
                    isSpecial: template.isSpecial,
                    specialDetail: specialDetail,
                    templateDesc: template.templateDesc,
                    isUpAiYun:vm.isUpload
                }).then(function (response) {
                   if (response.data.code=20000) {
                       if (ruleId!=0){
                           vm.$message.success('修改模板成功');
                       } else{
                           vm.$message.success('新增模板成功');
                       }

                   }else{
                       vm.$message.error('新增模板失败');
                   }
                })
            },
            checkTemplate(){
                let template = deepClone(vm.template);
                //公共的附加信息头
                if (template.isTitleAttachInfo) {
                    for (let i = 0; i < template.titleAttachInfoDetail.length; i++) {
                        let titleAttachInfoDetail = template.titleAttachInfoDetail[i];
                        let row=titleAttachInfoDetail.row;
                        let colList=titleAttachInfoDetail.colList;
                        if (!row){ //如果row没有就删除
                            template.titleAttachInfoDetail.splice(i,1);
                            i--;
                            continue;
                        }
                        for (let j = 0; j < colList.length; j++) {
                            let colval=colList[j];
                            let col= colval.col
                            if (!col){
                                colList.splice(j,1)
                                j--;
                            }
                        }
                    }
                }else{
                    template.titleAttachInfoDetail=null;
                }
                if (template.titleAttachInfoDetail && template.titleAttachInfoDetail.length) {
                    template.titleAttachInfoDetail= JSON.stringify(template.titleAttachInfoDetail)
                }else{
                    template.titleAttachInfoDetail=null;
                }

                //结束标志
                if (template.isEnd) {
                    for (let i = 0; i < template.endInfo.length; i++) {
                        if (!template.endInfo[i].trim()){
                            template.endInfo.splice(i,1);
                            i--;
                        }
                    }
                }else{
                    template.endInfo=null
                }

                if (template.endInfo&&template.endInfo.length) {
                    template.endInfo= JSON.stringify(template.endInfo)
                }else{
                    template.endInfo=null;
                }

                //循环信息头的信息
                if (template.isTitleInfo) {
                    for (let i = 0; i < template.titleInfoDetail.length; i++) {
                        let titleInfoDetail = template.titleInfoDetail[i];
                        let col=titleInfoDetail.col;
                        if (!col){ //如果row没有就删除
                            template.titleInfoDetail.splice(i,1);
                            i--;
                        }
                    }
                }else{
                    template.titleInfoDetail= null
                }

                if (template.titleInfoDetail&&template.titleInfoDetail.length){
                    template.titleInfoDetail= JSON.stringify(template.titleInfoDetail)
                } else{
                    template.titleInfoDetail= null
                }

                //multiSheetDetail多sheet的信息
                if (template.isMultiSheet) {
                    template.multiSheetDetail=JSON.stringify(template.multiSheetDetail)
                }else{
                    template.multiSheetDetail= null;
                }


                //isInputOut 流入流出标志
                template.isInputOut=JSON.stringify(template.isInputOut)

                //multiTitleHeadDetail 多标题头信息
                if (template.isMultiTitleHead) {
                    let colStr=template.multiTitleHeadDetail.col;
                    if (!colStr.trim()){
                        template.multiTitleHeadDetail=null
                    }
                }else{
                    template.multiTitleHeadDetail=null
                }

                //specialDetail 特殊模板
                if(template.isSpecial){
                    template.specialDetail=JSON.stringify(template.specialDetail)
                }else{
                    template.specialDetail=null
                }

                return template;
            },
            addEndInfo(){    //新增跳过的行
                vm.template.endInfo.push('')
            },
            removeEndInfo(index){//删除跳过的行
                if (vm.template.endInfo.length>1){
                    vm.template.endInfo.splice(index,1)
                }
            },
            addCommonAttachInfo(){  //动态新增公共的附加信息行
                let newVal = {row: '', colList:[{col:'', reg:'', obj:[{fieldName:'', fieldType:'', index:''}]}]}
                vm.template.titleAttachInfoDetail.push(newVal)
                console.log(vm.template.titleAttachInfoDetail)
            },
            removeCommonAttachRow(index){  //删除公共附加行
                if(vm.template.titleAttachInfoDetail.length>1){
                    vm.template.titleAttachInfoDetail.splice(index,1)
                }
            },
            addCommonAttachCol(index){ //动态新增公共的附加信息列
                let colVal={col:'',reg:'',obj:[{fieldName:'',fieldType:'',index:''}]}
                vm.template.titleAttachInfoDetail[index].colList.push(colVal)
            },
            removeCommonAttachCol(index){//删除公共附加列
                if (vm.template.titleAttachInfoDetail[index].colList.length>1){
                    vm.template.titleAttachInfoDetail[index].colList.splice(vm.template.titleAttachInfoDetail[index].colList.length-1,1)
                }
            },
            addCommonAttachColFiled(index1,index2){ //动态新增公共的附加信息列字段
                let filedVal={fieldName:'',fieldType:'',index:''}
                vm.template.titleAttachInfoDetail[index1].colList[index2].obj.push(filedVal)
            },
            removeCommonAttachColFiled(index1,index2){//删除公共的附加信息列字段
                if (vm.template.titleAttachInfoDetail[index1].colList[index2].obj.length>1){
                    vm.template.titleAttachInfoDetail[index1].colList[index2].obj.splice(vm.template.titleAttachInfoDetail[index1].colList[index2].obj.length-1,1)
                }
            },
            addTitleInfo(){  //添加标题头循环信息
                let obj={col:'',reg:'',obj:[{fieldName:'',fieldType:'',index:''}]}
                vm.template.titleInfoDetail.push(obj)
            },
            removeTitleInfo(index){  //删除标题头循环信息
                if (vm.template.titleInfoDetail.length>1){
                    vm.template.titleInfoDetail.splice(index,1)
                }
            },
            addTitleInfoFiled(index){//新增标题头字段
                let obj={fieldName:'',fieldType:'',index:''}
                vm.template.titleInfoDetail[index].obj.push(obj)
            },
            removeTitleInfoFiled(index){//删除标题头字段
                if (vm.template.titleInfoDetail[index].obj.length>1){
                    vm.template.titleInfoDetail[index].obj.splice(vm.template.titleInfoDetail[index].obj.length-1,1)
                }
            },
            addMultiSheet(){
                let obj= {sheetName:''}
                vm.template.multiSheetDetail.obj.push(obj)
            },
            removeMultiSheet(){
                if (vm.template.multiSheetDetail.obj.length>1){
                    vm.template.multiSheetDetail.obj.splice(vm.template.multiSheetDetail.obj.length-1,1)
                }
            },
            addMultiTitleHeadFiled(){
                let obj= {col:'',className:'com.mairuide.bill.DealFlow',classField:'',titleValues:'',fieldType:''}
                vm.template.multiTitleHeadDetail.map.push(obj)
            },
            removeMultiTitleHeadFiled(index){
                if (vm.template.multiTitleHeadDetail.map.length>1){
                    vm.template.multiTitleHeadDetail.map.splice(index,1)
                }
            },
            checkTempleteInfo(){ //验证必填项
                if(!vm.template.templateName){
                    vm.$message.error('模板名字不能为空');
                    return false;
                }
                if(!vm.template.titleHead){
                    vm.$message.error('标题头不能为空');
                    return false;
                }
                let i=0;
                for (let key in vm.template.isInputOut){
                    if(vm.template.isInputOut[key]){
                        i++;
                    }
                }
                if (i<=1){
                    vm.$message.error('收付标志信息不能为空');
                    return false;
                }
                return true;
            }
        }
    })
    // 判断是否为对象
    function isObject(o) {
        return (typeof o === 'object' || typeof o === 'function') && o !== null
    }
    // 迭代递归法：深拷贝对象与数组
    function deepClone(obj) {
        if (!isObject(obj)) {
            throw new Error('obj 不是一个对象！')
        }

        let isArray = Array.isArray(obj)
        let cloneObj = isArray ? [] : {}
        for (let key in obj) {
            cloneObj[key] = isObject(obj[key]) ? deepClone(obj[key]) : obj[key]
        }

        return cloneObj
    }
</script>
<style>
    .uploadFile{
        margin-left: 57px;
    }
    .uploadFile a {
        height: 30px;
    }
    .isEnd{
        margin-left: 57px;
    }
    .isEnd .el-input{
        width: 50%;
    }
    .commonAttachCol input{
        width: 290px;
    }
    .commonAttachCol .el-form-item label{
        width: 100px !important;
    }
    .commonAttachCol .el-form-item .el-form-item__content{
        margin-left: 100px !important;
    }
    .commonRow .el-input{
        width: 10%;
    }
    .commonAttachCol{
        margin-left: 100px;
        display: flex;
    }
    .commonAttachCol .el-form-item__content{
        margin-left: 100px; !important;
    }
    .commonAttachCol .el-button{
        width: 103px;
        height: 41px;
    }
    .commonAttachCol .commonAttachColField{
        padding-top: 50px;
        /*display: flex;
        margin-left: 100px;*/
    }
    .commonAttachCol .commonAttachColField .commonAttachColFieldBlock{
        display: flex;
    }
    .isTitleInfo {
        margin-left: 57px;
    }
    .isTitleInfo .isTitleInfoFiled{
        display: flex;
        margin-left: 100px;
    }
    .isTitleInfo .isTitleInfoFiled .el-input__inner{
        width: 280px;
    }
    .multiSheet{
        margin-left: 57px;
    }
    .multiSheet .multiSheetName{
        display: flex;
        margin-left: 100px;
    }
    .inputOut{
        margin-left: 57px;
    }
    .multiTitleHead{
        margin-left: 57px;
    }
    .multiTitleHead .multiTitleHeadField{
        display: flex;
        margin-left: 100px;
    }
    .special{
        margin-left: 57px;
    }
</style>
